
package makai.event;

import java.io.Serializable;
import java.util.Date;
import makai.canvas.Canvas;

/**
 * An Event is used to interact with the Canvas,
 * track canvas History, and synchronize multiple canvases.
 * 
 * @author Krechevskoy
 * @version 1.0
 */
public abstract class Event<T> implements Serializable, Cloneable {

    private final String name;
    private final Date time;

    /**
     * Constructs a new Event
     * 
     * @param name The name of this Event for display
     */
    public Event(String name) {
        this(name, new Date());
    }
    
    /**
     * Constructs a new Event
     * 
     * @param name The name of this Event for display
     * @param time The time of this Event to the nanosecond
     */
    public Event(String name, Date time) {
        this.name = name;
        this.time = time;
    }
    
    /**
     * Applies this Event to the Canvas
     * 
     * @param canvas The target Canvas
     */
    public abstract void apply(Canvas canvas);
      
    /**
     * Restores the Canvas to the way it was before the Event took place
     * 
     * @param canvas The target Canvas
     */
    public abstract void undo(Canvas canvas);
    
    /**
     * @return The name of this Event
     */
    public String getName(){
        return name;
    }

    /**
     * @return The time this Event was performed
     */
    public Date getTime(){
        return time;
    }
    
    @Override
    public String toString() {
        return "Event["+getName()+"]";
    }

    @Override
    protected abstract Event<T> clone() throws CloneNotSupportedException;
    
}
